<template>
	<view class="container">
		<uni-nav-bar :title="status == 'add' ? '调拨入库':'调拨入库详情'" fixed statusBar :border="false" height="88rpx" left-icon="left" @clickLeft="onClickLeft" :right-text="status === 'add' ? '导入':''" @clickRight="addInwarehouse"></uni-nav-bar>
		<view class="content">
			<view class="card">
				<view class="title" v-if="status == 'add'">
					<text>调拨详情</text>
				</view>
				<view class="line">
					调拨单号：{{ dbFollowData.allocationNumber }}
				</view>
				<view class="line">
					<view class="left">
						出库门店：{{ dbFollowData.allocationStoreName }}
					</view>
					<view class="right">
						收货门店：{{ dbFollowData.receiveStoreName }}
					</view>
				</view>
				<view class="line" v-if="status === 'add'">
					调拨日期：{{ dbFollowData.allocationTime | parseTime }}
				</view>
				<view class="line" v-else>
					入库日期：{{ dbFollowData.createTime | parseTime }}
				</view>
			</view>
			<view class="card">
				<view class="title">
					商品明细
				</view>
				<view class="item" v-for="(item,index) in storeDbList" :key="item.id">
					<view class="line">
						<view class="left u-ellipsis" style="width: 60%;">
							{{ item.commodityName }}
						</view>
						<view class="right" style="width: 40%;">
							数量：{{ item.allocationCount }}
						</view>
					</view>
					<view class="line">
						<view class="left">
							一维码：{{ item.barCode }}
						</view>
						<view class="right">
							配送规格：{{item.deliveryNorms}}
						</view>
					</view>
					<view class="line">
						<view class="left">
							生产日期：{{ item.manufactureTime | parseTime('YYYY-MM-DD') }}
						</view>
						<view class="right">
							件数：{{ item.allocationNumber }}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { reqDbdInwarehouseList,reqDbdInwarehouse,reqFollowDetail } from '@/apis/goods';
	export default {
		name: 'ShDetail',
		data() {
			return {
				allocationNumber: '',
				dbFollowData:{
					warehouseName:'',
					storeName:'',
					createTime:'',
				},
				storeDbList:[],
				status:'',
			}
		},
		onLoad(params) {
			this.allocationNumber = params?.allocationNumber;
			this.status = params?.status;
			if(this.allocationNumber != '' && this.status == 'add'){
				this.getFollowData();
			}else {
				console.log('详情');
				this.getFollowDetail();
			}
		},
		methods: {
			async getFollowData() {
				let res = await reqDbdInwarehouseList({allocationNumber:this.allocationNumber});
				if(res.code === 200) {
					this.dbFollowData = res.data;
					this.storeDbList = res.data.detailsList;
				}
			},
			async getFollowDetail(){
				let res = await reqFollowDetail({id:this.allocationNumber});
				if(res.code === 200) {
					this.dbFollowData = res.data;
					this.storeDbList = res.data.detailsList;
				}
			},
			async addInwarehouse() {
				if(this.status != 'add') return ;
				let res = await reqDbdInwarehouse({allocationNumber:this.allocationNumber});
				if(res.code === 200){
					uni.utils.toast('导入成功');
					setTimeout(()=>{
						this.$navBack();
					},1500)
				}
			}
		},
	}
</script>

<style>
	page {
		background: #f7f7f7;
	}
</style>
<style lang="scss" scoped>
	.content {
		padding: 20rpx;
		box-sizing: border-box;
		
		.card {
			background: #fff;
			width: 100%;
			// padding: 15rpx 10rpx;
			border-radius: 15rpx;
			margin-bottom: 15rpx;
			box-sizing: border-box;
			padding: 10rpx 30rpx;
			.title {
				display: flex;
				font-weight: bold;
				font-size: $uni-font-size-big;
				color: $uni-main-bgColor;
				padding: 15rpx 0;
				border-bottom: 0.5px solid #ccc;
				box-sizing: border-box;
				align-items: center;
				justify-content: space-between;
			}
			.line {
				line-height: 50rpx;
				font-size: $uni-font-size-small;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.left {
					width: 50%;
					text-align: left;
				}

				.right {
					width: 50%;
					text-align: right;
				}
			}
			.item {
				border-bottom: 1px dashed #ccc;
				&:last-child{
					border: none;
				}
			}
		}
	}
</style>